﻿using System;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Web;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.UrlReferrer != null &&
            HttpContext.Current.Request.UrlReferrer.ToString().Contains("RetrivePassword"))
        {
            ltrPasswordMessage.Visible = true;
        }
    }
    protected void btnLogin_click(object sender, EventArgs e)
    {
        Bintje.bintje.imageoSession ses;
        if (BintjeMembershipProvider.ValidateUser(txtUsername.Text.Trim(), txtPassword.Text.Trim(), out ses))
        {
            FormsAuthentication.SetAuthCookie(txtUsername.Text.Trim(), true);
            ltrLoginMessage.Visible = false;
            ((Label)this.Page.Master.FindControl("lblloginStat")).Text = string.Format("Welcome {0},", txtUsername.Text.Trim());
            ((Label)this.Page.Master.FindControl("lblloginStat")).Visible = true;
            ((LinkButton)this.Page.Master.FindControl("lnkLogout")).Visible = true;
            Session["UserId"] = ses.userId;
            Session["Session"] = ses;
            
            pnllogin.Visible = false;
            ((HyperLink)this.Page.Master.FindControl("lnkSignup")).Visible = false;
            if (Request["Retuenurl"] != null)
            {
                Response.Redirect(Request["Retuenurl"]);
            }
            Response.Redirect("~/UI/Home.aspx");
        }
        else
        {
            ltrLoginMessage.Visible = true;
            pnllogin.Visible = true;
            ((HyperLink)this.Page.Master.FindControl("lnkSignup")).Visible = true;
        }
    }
}
